<?php
namespace Home\Controller;
use Think\Controller;
class CharityController extends Controller {
    public function index() {
        $c = D('Charity');
        $list = $c->order('id desc')->limit(8)->select();
        $r = D('Resource');
        foreach ($list as &$v) {
            $pic = $r->where('id=%d', $v['pid'])->find();
            $v['path1'] = $pic['path'];
            $pic = $r->where('id=%d', $v['pid2'])->find();
            $v['path2'] = $pic['path'];
            $strings = explode('.', number_format($v['amount'], 2));
            $v['integer'] = $strings[0];
            $v['decimal'] = $strings[1];
        }

        $this->assign('list1', array_slice($list, 0, 4));
        count($list)>4 && $this->assign('list2', array_slice($list, 4, 4));
        
        $this->display('./Public/charity.html');
    }
}